﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBLClient.DBLAdminConfigService;
using DBLClient;
namespace DBLClient.DBLForm
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
            textBoxPassword.UseSystemPasswordChar = true;
            textBoxLoginName.Focus();
        }

        private void buttonLogin_Click(object sender, EventArgs e)
        {
            string error = checkTextBoxInput();
            if (error == null)//no error
            {
                try
                {
                    AdminConfigService acs = new AdminConfigService();
                    DataSet ds = acs.AdminLogin(textBoxLoginName.Text, textBoxLoginName.Text);
                    if (ds == null)
                    { MessageBox.Show("用户名或密码错误，找不到此用户"); }
                    else
                    if (ds.Tables[0].Rows.Count == 1)
                    {
                        OnlineUserInfo.USERNAME = ds.Tables[0].Rows[0]["adminname"].ToString();
                        OnlineUserInfo.LEVEL = ds.Tables[0].Rows[0]["adminlevel"].ToString();

                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            { MessageBox.Show(error,"错误"); }
        }
        /// <summary>
        /// 检查用户名密码是否为空，如果为空返回错误信息，如果正确，返回null
        /// </summary>
        /// <returns></returns>
        private string checkTextBoxInput()
        {
            if (textBoxLoginName.Text == null || textBoxLoginName.Text.Equals(""))
            {
                return "请输入用户名";
            }
            if (textBoxPassword.Text == null || textBoxPassword.Text.Equals(""))
            {
                return "请输入密码";
            }
            return null;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            AdminConfigService admin = new AdminConfigService();

            MySoapHeader token = new MySoapHeader();
            token.userName = "test";
            token.passWord = "test";

            admin.MySoapHeaderValue = token;

            try
            {
                string s = admin.HelloWorld();
                MessageBox.Show(s);
            }
            catch (Exception ee) 
            {
                MessageBox.Show(ee.ToString());
            }
        }
    }
}
